<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <link rel="stylesheet" href="./highlight/styles/agate.css"> 
    <script src="./highlight/highlight.pack.js"></script> 
    <script > hljs.initHighlightingOnLoad();</script>
    <script src="./js/my-pre.js"></script>
</head>
<body>
    <div id="app">
       <child-a>
           <template scope="props">
               <p>来自父组件的内容</p>
               <p>{{props.msg}}</p>
           </template>
       </child-a>
       <hr>
       <my-list :books="books">
            <template slot="book" scope="props">
                <li>{{props.bookName}}</li>
            </template>
        </my-list>
        <hr>
        <h1>访问slot,主要还是通过 $slots.name方法来实现</h1>

    </div>
    
    <script>

        Vue.component('child-a',{
            template:'\
                    <div class="container">\
                        <slot msg="来自子组件的内容"></slot>\
                        </div>'
                        
        })

        Vue.component('my-list',{
            props:{
                books:{
                    type:Array,
                    default:function(){
                        return []
                    }
                }
            },
            template:'\
                <ul>\
                    <slot name="book" v-for="book in books" :book-name="book.name">\
                        </slot>\
                        </ul>'
        });

        new Vue({
            el: '#app',
            data: {
                books:[
                    {name:'vue'},
                    {name:'java'},
                    {name:'python'}
                ]
            }
        })
    </script>
    
</body>
</html>